package 多线程.指令重排序;

/**
 * @author : K k
 * @date : 11:00 2020/10/15
 */
public class ResortDemo {
    static int a=0,b=0;
    static int x=0,y=0;

    public static void main(String[] args) {
        Thread thread1 = new Thread(new Runnable() {
            @Override
            public void run() {
                a = 1;
                x = b;
            }
        });
        Thread thread2 = new Thread(new Runnable() {
            @Override
            public void run() {
                b = 2;
                y = a;
            }
        });
        thread2.start();
        thread1.start();
        try {
            thread1.join();
            thread2.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("a"+a+" b"+b+" x"+x+" y"+y);
    }
}
